package com.afdor.rws.event.driven.channel.local;

import com.afdor.rws.event.driven.api.channel.consumer.EventConsumer;
import com.afdor.rws.event.driven.channel.local.observer.ObserverEventListener;
import com.afdor.rws.event.driven.entities.Event;
import lombok.NonNull;

import java.util.Optional;


/**
 * 事件消息监听
 *
 * @author 悭梵
 * @date Created in 2018-08-08 14:04
 */
public class LocalObserverEventListener implements ObserverEventListener {

    private EventConsumer eventConsumer;

    public LocalObserverEventListener(@NonNull EventConsumer eventConsumer) {
        this.eventConsumer = Optional.ofNullable(eventConsumer).orElseThrow(() -> new IllegalArgumentException("消费者为空"));
    }

    @Override
    public void onEvent(@NonNull Event event) {
        this.eventConsumer.getEventHandler().handler(event);
    }
}
